
	/** *************定义学生列表数据************ */
	var graduateManageProxy = new Ext.data.HttpProxy({url: "graduate/graduateListAction!teacherExecute.action"});
	var graduate = Ext.data.Record.create([
		{name: "id", type: "int", mapping: "id"},
		{name: "number", type: "string", mapping: "number"},
		{name: "gender", type: "string", mapping: "gender"},
		{name: "name", type: "string", mapping: "name"},
		{name: "paper", type:"paper", mapping:"paper"/*,convert:function(v){return v? v.title:"未提交";}*/},
		{name: "paperState", type:"string", mapping:"paper",convert:function(v){return v? v.strState:"未提交";}}
		//{name: "email", type: "string", mapping: "email"}
	]);
	var graduateManageReader = new Ext.data.JsonReader(
		{totalProperty: "totalProperty", root: "root"},
		graduate
	);
	var graduateManageStore = new Ext.data.Store({
		proxy: graduateManageProxy,
		reader: graduateManageReader
		// autoLoad:true
	});
	
	/** ***************定义行列模型***************** */
	// 列模型
	var cm = new Ext.grid.ColumnModel([
		new Ext.grid.RowNumberer(),
		{header: "学生编号", width: 100, dataIndex: "number",sortable:true},
		{header: "姓名", width: 80,dataIndex: "name",sortable:true},
		{header: "性别", width: 80,dataIndex: "gender",sortable:true},
		{header: "已提交论文", width: 120,dataIndex: "paper",
			renderer: function(v){
				if(v){
					return "<a href='upload/"+v.file+"'>"+v.title+"</a>";
				}else{
					return "未提交";
				}
			}
		},
		{header: "论文状态", width: 120,dataIndex: "paperState"}
		//{header: "邮箱", width: 150, dataIndex: "email"}
	]);
		
	var bbar = new Ext.PagingToolbar({
		store: graduateManageStore,
		pageSize: 10,// 页大小
		displayInfo: true,// 是否显示displayMsg
		displayMsg: "第{0}条到第{1}条,共{2}条",
		emptyMsg: "没有记录"// 如果没有记录，则显示该文本
	});
	
	/** ***************定义主体panel***************** */
	var graduateManageGrid = new Ext.grid.GridPanel({
		region:'center',
		closable:true,
		//title: "学生列表",
		//height: 200,
		width: 400,
		frame:true,
		cm: cm,
		store: graduateManageStore,
		bbar:bbar
	});		
	
	graduateManageGrid.on('rowdblclick',function(grid,index,e){
		var _rec = graduateManageGrid.store.getAt(index);//取出点击的那条记录
		var _paper = _rec.get("paper");
		if(_paper){
			//if(_paper.state == 0){
				new addOrModifyFn("comment/commentAddAction",_paper);
/*			}else{
				new addOrModifyFn("comment/commentModifyAction",_paper);
			}*/
		}
	});
	
	var commentInfoForm = new Ext.form.FormPanel({
		id:"commentInfoForm",
		frame:true,
		bodyStyle:"padding:5px 5px 0",
		border:false,
		waitMsgTarget:true,// true的意思是说表单提交时的等待信息在这个表单之内显示，而不是弹出框(进度条形式的)
		labelAlign:"right",
		labelPad : 10,// 标签与字段录入框之间的空白
		defaults:{width:230/*,disabled:true*/},
		//defaultType:"textfield",
		items:[{
				xtype:"combo",
				name:"passText",
				hiddenName:"pass",
				fieldLabel:"是否通过",
				store:new Ext.data.SimpleStore({
						fields: ['value','display'],
						data: [["yes","是"],["no","否"]]
					}),
				triggerAction: 'all',
				displayField:"display",
				valueField:"value",
				mode:"local",
				//readOnly:true,
				allowBlank:false,
				emptyText:""
			},{
				fieldLabel:"意见及建议",
				name:"comment.content",
				xtype:"textarea",
				allowBlank:false,
				emptyText:"填写意见及建议"
			},{
				name:"comment.id",
				xtype:"hidden",
				value:0
			}]
	});
	
	var addOrModifyFn = function(_url, _paper){
		new Ext.Window({
			id:"addOrModifyWin",
			width:400,
			autoHeight:true,
			resizable:false,// 不可以调整大小
			draggable:false,// 不可移动
			modal:true,// 设置此Window为模式窗口,
			//animateTarget:'addBtn',
			items:[
				new Ext.form.FormPanel(commentInfoForm)
			],
			buttonAlign:'center',
			minButtonWidth:60,
			buttons:[{
				text:"提交",
				tooltip:"提交数据",
				handler:function(){new addOrModifyCommitFn(_url,_paper);}
			},{
				text:"取消",
				tooltip:"取消此操作",
				handler:function(){
					Ext.getCmp("addOrModifyWin").close();//关闭窗口
				}
			}]			
		}).show();
		
/*		if(_paper.state!=0){
			var _form = Ext.getCmp("commentInfoForm").getForm();
			_form.reader =  new Ext.data.JsonReader({
									root:"paper"
								},[
							       {name:"pass",type:"string",mapping:"state",convert:function(v){return v==1?"yes":"no"}},
							       {name:"comment.content",type:"string",mapping:"comment.content"},
							       {name:"comment.id",type:"int",mapping:"comment.id"}
							       {name:"graduate.email",type:"string",mapping:"email"}							    ]);
			_form.load({url:"paper/paperInfoAction!teacherExecute",
						params: {paperId: _paper.id},
						waitMsg: '正在载入数据...',
						method:'POST',
						success:function(form, action){
							 Ext.example.msg("提示","数据加载成功……","msg-box-success");						},
						failure:function(){
							Ext.Msg.alert("异常","数据加载失败","msg-box-error");
							Ext.getCmp("addOrModifyWin").close();
						}						
					});
		}*/
	}
	
	var addOrModifyCommitFn = function(_url,_paper){
		if(Ext.getCmp("commentInfoForm").getForm().isValid()){// 对表单进行验证(根据配置的项进行配置)
			Ext.getCmp("commentInfoForm").getForm().submit({// 利用表单的submit方法提交表单
				params:{paperId:_paper.id},
				waitTitle:"请稍候",					// 提交表单时进度条的标题
				waitMsg:"正在提交数据，请稍后……",		// 提交表单时进度条的信息
				url:_url,							// 提交地址
				method:"POST",						// 提交方式，需要大写
				success:function(form, action){		// 如果提交成功后处理的方法
					//Ext.Msg.alert("提交成功", "提交学生信息成功","msg-box-success");// 相应的提示信息
					// Ext.getCmp("addOrModifyWin").close();
					// //根据id获取到表单的窗口，然后将其关闭
					graduateManageGrid.getStore().reload();				// 提交成功后，需要刷新GridPanel数据，
					Ext.getCmp("addOrModifyWin").close();										// 但效率时会将提交表单中的数据直接添加或更新到GridPanel中
				},
				failure:function(form,action){			// 提交指失败进处理的方法
					Ext.Msg.alert("警告","数据提交失败，请核对","msg-box-error");
				}								
			});	
			
		} else {// 如果表单验证未通过则提示用户骓未通过。
			Ext.Msg.alert("提示","请填写完整、合法的信息","msg-box-error");
		}		
	}
	
	Ext.onReady(function(){	
	
		Ext.BLANK_IMAGE_URL = "extjs/resources/images/default/s.gif";
	
		Ext.QuickTips.init();	
		
		var viewPort = new Ext.Viewport({
				layout : 'fit',
				items : [graduateManageGrid]　　　            
			});
		graduateManageStore.load({params: {start: 0, limit: 10}});		
	});